package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.EntrustApprove;
import com.prs.crm.service.sys.EntrustApproveService;

public class EntrustApproveAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private String types;
	private EntrustApprove entrustApprove;
	private EntrustApproveService entrustApproveService;
	public String getTypes() {
		return types;
	}
	public void setTypes(String types) {
		this.types = types;
	}
	public EntrustApprove getEntrustApprove() {
		return entrustApprove;
	}
	public void setEntrustApprove(EntrustApprove entrustApprove) {
		this.entrustApprove = entrustApprove;
	}
	public EntrustApproveService getEntrustApproveService() {
		return entrustApproveService;
	}
	public void setEntrustApproveService(EntrustApproveService entrustApproveService) {
		this.entrustApproveService = entrustApproveService;
	}
	@Action("editEntrustApproves")
	public String editEntrustApproves(){
		this.entrustApprove=this.getEntrustApproveService().getEntrustApprove(types);
		return SUCCESS;
	}
	@Action("editEntrustApprove")
	public String editEntrustApprove(){
		this.entrustApprove=this.getEntrustApproveService().getEntrustApprove("ea01");
		return SUCCESS;
	}
	@Action(value="saveEntrustApprove",results={
			@Result(name="success",type="redirect",location="editEntrustApproves?types=${entrustApprove.getType()}"),
			@Result(name="error",type="chain",location="editEntrustApproves?types=${entrustApprove.getType()}")
	})
	public String saveEntrustApprove(){
		EntrustApprove ea=this.getEntrustApproveService().getEntrustApprove("ea01");
		if(ea==null){
			ea=new EntrustApprove();
			ea.setType("ea01");
			ea.setPerson(entrustApprove.getPerson());
			ea.setDate(entrustApprove.getDate());
			ea.setState(entrustApprove.getState());
			this.getEntrustApproveService().save(ea);
		}else{
			this.getEntrustApproveService().submit(ea);
		}
		entrustApprove=ea;
		return SUCCESS;
	}
}
